package com.zbkj.front.controller;

//import com.zbkj.common.model.InOrOutWarehouseOrders;
//import com.zbkj.common.model.InOrOutWarehouseSkuDetails;
import com.zbkj.common.model.saleroom.SaleRoom;
import com.zbkj.common.model.saleroom.TransferInfo;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.ProductAndProductAttrValueResponse;
import com.zbkj.common.response.RefundOrderResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.front.service.EmployeeOrderService;
import com.zbkj.service.service.RefundOrderService;
import com.zbkj.service.service.saleroom.ISaleRoomService;
import com.zbkj.service.service.saleroom.ITransferInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;


@Api("门店-商品管理")
@RestController
@RequestMapping("api/front/sale/room")
public class SaleRoomController {

    @Autowired
    private ISaleRoomService saleRoomService;
    @Autowired
    private EmployeeOrderService employeeOrderService;
    @Autowired
    private RefundOrderService refundOrderService;
    @Autowired
    private ITransferInfoService transferInfoService;


    @ApiOperation("查询门店商品信息列表")
    @PostMapping("/product/list")
    public CommonResult<CommonPage<ProductAndProductAttrValueResponse>> list(@RequestBody @Valid SaleRoomProductRequest saleRoomProductRequest) {
        return CommonResult.success(CommonPage.restPage(saleRoomService.selectSaleRoomProductList(saleRoomProductRequest)));
    }


    @ApiOperation("查询门店订单列表")
    @PostMapping("/order/list")
    public CommonResult<Map<String, Object>> orderList(@RequestBody SaleRoomOrderRequest saleRoomOrderRequest) {
        return CommonResult.success(saleRoomService.selectOrderList(saleRoomOrderRequest));
    }


    @ApiOperation("查询调货详情列表")
    @GetMapping("/list")
    public CommonResult<CommonPage<TransferInfo>> list(PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(transferInfoService.selectTransferInfoListByRoomId(pageParamRequest)));
    }


    @ApiOperation("确认调货")
    @GetMapping("/isSure/{transferInfoId}")
    public CommonResult<Boolean> isSure(@PathVariable(value = "transferInfoId") Integer transferInfoId) {
        return CommonResult.success(transferInfoService.isSure(transferInfoId));
    }


    @ApiOperation(value = "核销码核销订单详情")
    @RequestMapping(value = "/get/verification", method = RequestMethod.POST)
    public CommonResult<String> getVerificationOrder(@RequestBody @Validated OrderVerificationRequest request) {
        return CommonResult.success(employeeOrderService.getVerificationOrderByCode(request.getVerifyCode()));
    }


    @ApiOperation(value = "核销码核销订单")
    @RequestMapping(value = "/verification", method = RequestMethod.POST)
    public CommonResult<Object> verificationOrder(@RequestBody @Validated OrderVerificationRequest request) {
        return CommonResult.success(employeeOrderService.verificationOrderByCode(request.getVerifyCode()));
    }


    @ApiOperation(value = "退款单审核-退钱")
    @RequestMapping(value = "/audit", method = RequestMethod.POST)
    public CommonResult<String> audit(@RequestBody @Validated OrderRefundAuditRequest request) {
        if (refundOrderService.audit(request, 2)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    @ApiOperation(value = "退款申请-拒绝")
    @RequestMapping(value = "/refund/reject", method = RequestMethod.POST)
    public CommonResult<String> receivingReject(@RequestBody @Validated RejectReceivingRequest request) {
        if (refundOrderService.receivingReject(request, 2)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    @Deprecated
    @ApiOperation(value = "同城配送-预约配送-查询最近的一个配送中心")
    @RequestMapping(value = "/select/recently", method = RequestMethod.POST)
    public CommonResult<SaleRoom> selectRecently(@RequestBody @Validated PositionRequest positionRequest) {
        return CommonResult.success(saleRoomService.selectRecently(positionRequest));
    }


    @ApiOperation("根据城市查询配送中心列表")
    @PostMapping("/select/list")
    public CommonResult<CommonPage<SaleRoom>> listByCity(@RequestBody @Valid CityRequest cityRequest) {
        return CommonResult.success(CommonPage.restPage(saleRoomService.listByCity(cityRequest)));
    }


    @ApiOperation("查询所有门店所在的城市列表-去重")
    @PostMapping("/select/city/list")
    public CommonResult<CommonPage<String>> listByCity(@RequestBody @Valid PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(saleRoomService.listCityList(pageParamRequest)));
    }


    @ApiOperation(value = "门店退款订单列表")
    @RequestMapping(value = "/refund/order/list", method = RequestMethod.POST)
    public CommonResult<CommonPage<RefundOrderResponse>> refundOrderList(@RequestBody @Valid ReturnOrderListRequest returnOrderListRequest) {
        return CommonResult.success(CommonPage.restPage(saleRoomService.getRefundOrderList(returnOrderListRequest)));
    }


//    @ApiOperation(value = "门店出入库单分页列表")
//    @RequestMapping(value = "/list", method = RequestMethod.POST)
//    public CommonResult<CommonPage<InOrOutWarehouseOrders>> getList(@RequestBody @Valid InOrOutWarehouseOrdersRequest inOrOutWarehouseOrdersRequest) {
//        CommonPage<InOrOutWarehouseOrders> inOrOutWarehouseOrdersCommonPage = CommonPage.restPage(saleRoomService.getListByStatus(inOrOutWarehouseOrdersRequest));
//        return CommonResult.success(inOrOutWarehouseOrdersCommonPage);
//    }
//
//    @ApiOperation(value = "门店出入库单详情")
//    @RequestMapping(value = "/info", method = RequestMethod.POST)
//    public CommonResult<CommonPage<InOrOutWarehouseSkuDetails>> getList(@RequestBody @Valid IdRequest idRequest) {
//        return CommonResult.success(CommonPage.restPage(saleRoomService.info(idRequest)));
//    }
//
//
//    @ApiOperation(value = "门店出入库单详情操作(取消-提交)")
//    @RequestMapping(value = "/operate", method = RequestMethod.POST)
//    public CommonResult<Boolean> operate(@RequestBody @Valid OperateRequest operateRequest) {
//        return CommonResult.success(saleRoomService.operate(operateRequest));
//    }
}